<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Prettus\Repository\Contracts\Transformable;
use Prettus\Repository\Traits\TransformableTrait;

/**
 * CMain.
 *
 * @package namespace App\Models;
 */
class DormRatingMain extends BaseModel implements Transformable
{
    use TransformableTrait;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = ['user_id', 'company_id', 'dorm_id', 'period_id', 'get_score', 'total_score', 'remark'];
    public function dorm()
    {
        return $this->belongsTo(Dorm::class);
    }
    public function period()
    {
        return $this->belongsTo(Period::class);
    }

    public function dormRatings()
    {
        return $this->hasMany(DormitoryRating::class);
    }
    public function user()
    {
        return $this->belongsTo(User::class);
    }

    protected static function boot()
    {
        parent::boot();
        static::deleting(function ($order) {
            $order->dormRatings()->delete();
        });
    }
}
